#include <threadExcuter.h>
void threadExcuterInit(struct threadExcuterInform *threadExcut, void *(*threadCallBack)(void *), void *setUserData)
{
    if(!threadExcut)
    {
        logerror("");
        return;
    }
    threadExcut->threadFd = 0;
    threadExcut->threadRunflag = 0;
    threadExcut->threadCallBack = threadCallBack;
    threadExcut->userData = setUserData;
}
void threadExcuterBegin(struct threadExcuterInform *threadExcut)
{
    int tmpflag = 0;
    if(!threadExcut)
    {
        logerror("");
        return;
    }
    threadExcuterQuit(threadExcut);
    if(!threadExcut->threadCallBack)
    {
        logerror("");
        return;
    }
    threadExcut->threadRunflag = 1;
    tmpflag = pthread_create(&threadExcut->threadFd, NULL, threadExcut->threadCallBack, threadExcut);
    if(tmpflag < 0)
    {
        logerror("%d", tmpflag);
    }
    logdebug("begin finish:%ld", (long)threadExcut->threadFd);
}

void threadExcuterQuit(struct threadExcuterInform *threadExcut)
{
    if(!threadExcut)
    {
        logerror("");
        return;
    }
    threadExcut->threadRunflag = 0;
    if(threadExcut->threadFd > 0)
    {
        pthread_join(threadExcut->threadFd, NULL);
        logdebug("quit finish:%ld", (long)threadExcut->threadFd);
        threadExcut->threadFd = 0;
    }
}